<?php
namespace Student\Controller;
use Think\Cache\Driver\Memcache;
use Think\Controller;

class TestController extends Controller{
    public function add(){
        if(IS_POST){
            $name=I('name');
            $department=I('department');
            $subject=I('subject');
            $score=I('score');
            $time=I('time');
            $data=array(
                'name'=>$name,
                'department'=>$department,
                'subject'=>$subject,
                'score'=>$score,
                'time'=>$time
            );
            $id=M('class')->add($data);
            dump($id);
            if(!$id===false){
                echo"操作成功，ID为".$id;
            }else{
                echo"操作失败";
            }

        }else {
            $this->display();

        }

    }
    public function find1(){

        $data['_string']='time=16 AND department="软件工程系"';
        $id=M('class')->where($data)->avg('score');
        echo"软件工程系的学生16年的平均成绩为：$id 分";

    }
    //复合查询
    public function find2(){

        $data['department']="多媒体系";
        $data['subject']="高数";
        $data['time']="15";
        $data['score']=array(array('gt',80),array('lt',100));
        $id=M('class')->where($data)->select();
        echo "<pre>";
        print_r($id);

    }
    //模糊查询
    public function find3(){
        $data['score']=array('like',"9%");
        $id=M('class')->where($data)->select();
        echo "<pre>";
       print_r($id);
    }
    public function find4(){
        if (IS_POST){
        $name=I('name');
            $data['name']=$name ;

        $id=M('class')->where($data)->select();
        echo "<pre>";
        dump($id);

    }else{
            $this->display();
        }

}
}
